package _001_TwoSum;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class TwoSum02 {
	public static void main(String[] args) {
		int[] nums = {2, 7, 11, 15};
		int target = 9;
		System.out.println(Arrays.toString(new TwoSum02().twosum(nums, target)));
	}
	
	public int[] twosum(int[] nums, int target) {
		Map<Integer, Integer> map = new HashMap<>();
		for(int i = 0; i < nums.length; i++) {
			map.put(nums[i], i);
		}
		for (int i = 0; i < nums.length; i++) {
			int temp = target - nums[i];
			if(map.containsKey(temp) && map.get(temp) != i) {
				return new int[] {i, map.get(temp)};
			}
		}
		return null;
	}
}
